package com.itlzh.mall.user.controller;

import com.itlzh.mall.common.dto.UserReceiveAddressDTO;
import com.itlzh.mall.common.result.Result;
import com.itlzh.mall.user.service.IUserReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/address")
public class UserReceiveAddressController {
    @Autowired
    private IUserReceiveAddressService userReceiveAddressService;

    /**
     * 添加地址
     * @param userReceiveAddress
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody UserReceiveAddressDTO userReceiveAddress){
        userReceiveAddressService.save(userReceiveAddress);
        return Result.success();
    }
    @GetMapping("/{userId}")
    public Result list(@PathVariable Long userId){
        List<UserReceiveAddressDTO> userReceiveAddresses = userReceiveAddressService.listByUserId(userId);
        return Result.success(userReceiveAddresses);
    }

}
